var orderIntTxnCd = $.trim($("#orderIntTxnCd").val());
$(function(){
    $(".tabsUl .tabsLabel").click(function(){
        var currentIdx = $(this).parent().find(".cur").index()-1,
            selectIdx = $(this).index()-1;
        if(selectIdx == currentIdx) {return false;}
        $(this).siblings("li").removeClass("cur");
        $(this).addClass("cur");

        var clickId = $(this).prop("id");
        showChannelById(clickId);
    });

    var payChannel = $("#defalutPayChannel").val();
    if($("#orderIntTxnCd").val()=="00200"){
        payChannel="";
    }
    showChannel(payChannel);
});

function autoSortTag(show){
    var num = [];
    $("#channelSelLi li").each(function(i,domele){
        if($(this).attr("index")!=-1){
            num.push($(this).attr("index"));
        }
    });
    num = num.sort(function(a,b){
        return a-b;
    });
    $.each(num,function(i,v){
        if(i>0){
            $("#channelSelLi li[index='"+v+"']").insertAfter($("#channelSelLi li[index='"+num[i-1]+"']"));
        }
    });
    if(show){
        var channel = $("#channelSelLi li[index='"+num[0]+"']");
        channel.addClass("cur");
        showChannelById(channel.prop("id"));
    }
}
var gopayLoginPwdCtrl;//登录

function showTabHide(t1,t2,t3, t4){
    if(t1==1){
        $("#bankPayTab").show();
        onLineBankShow();
        if($("#loginEmail").val() != ""){
            $("#expressLoginBtnDiv").hide();
            $("#bankLoginBtnDiv").show();
        }
    }else{
        $("#bankPayTab").hide();
    }
    if(t2==1){
        $("#gopayTab").show();
        //if(!gopayLoginPwdCtrl && $("#gopayLoginPwdCtrlDiv").length>0){
        //    gopayLoginPwdCtrl=new PwdControl("password","gopayLoginPwdCtrlDiv",252,38);
        //}
        if(!pgeditor && $("#gopayLoginPwdCtrlDiv").length>0){
            pgeditor.pgInitialize();
        }
    }else{
        $("#gopayTab").hide();
    }
    if(t3==1){
        $("#expressPayTab").show();
        if($("#loginEmail").val() != ""){
            $("#expressLoginBtnDiv").show();
            $("#bankLoginBtnDiv").hide();
        }
        if($("#exCardId_1").length > 0){
            $(".close-more").trigger("click");
        }
    }else{
        $("#expressPayTab").hide();
    }
//add by dongdh 20160809
    if (t4 == 1) {
        $("div[id$='PayTab']").hide();
        $("#scanPayTab").show();

        if($("#loginEmail").val() != ""){
            //登录后的
            $("#expressLoginBtnDiv").hide();
            $("#bankLoginBtnDiv").hide();
            ///判断是否有账户  如果没有账户 不显示下一步按钮
            var acctLen = $('#gopayAcctIdSel').length; //账户长度
            if (acctLen > 0) {
                $("#submitLocBtn16").show();
            }
        }

    } else {
        $("#scanPayTab").hide();
        $("#submitLocBtn16").hide();
    }

}
function showChannel(channel){
    var showTag = false;
    if(channel=="01"){
        showTabHide(1,0,0);
    }else if(channel=="06"){
        showTabHide(0,1,0);
    }else if(channel=="02"){
        showTabHide(0,0,1);
    }else{
        showTag = true;
    }
    autoSortTag(showTag);
}

function showChannelById(clickId){
    if(clickId == "gopayChannelSel"){
        showTabHide(0,1,0);
    }if(clickId == "expressChannelSel"){
        showTabHide(0,0,1);
    }else if(clickId == "bankChannelSel"){
        showTabHide(1,0,0);
    } else if (clickId == 'scanChannelSel') {
        showTabHide(0, 0, 0, 1);
    }
}
